package com.mioto.ld.module.device.model.app;

import cn.hutool.core.util.StrUtil;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.mioto.ld.communication.mqtt.MqttHelper;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author mioto-qinxj
 * @date 2024/6/8
 * @desc
 */
@Getter
@Setter
@ApiModel("app首页数据集合-设备位置分类统计")
public class AppDeviceMainPageAddressVO {
    @ApiModelProperty("邮编")
    private String postalCode;

    @ApiModelProperty("设备地址")
    private String address;

    @ApiModelProperty("设备总数量")
    private int totalCount;

    @ApiModelProperty("故障数量")
    private int faultCount;
    @ApiModelProperty("经纬度")
    private String location;
    @ApiModelProperty("所有设备id列表")
    private int[] deviceIds;
    @ApiModelProperty("在线设备id列表")
    private List<Integer> onlineDeviceIds= new ArrayList<>(4);
    @ApiModelProperty("离线设备id列表")
    private List<Integer> offlineDeviceIds = new ArrayList<>(4);
    /**
     * 设备序列号
     */
    @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
    private String deviceSn;
    /**
     * 设备id
     */
    @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
    private String deviceId;

    public void setDeviceId(String deviceId){
        if (StrUtil.isNotEmpty(deviceId)){
            deviceIds = StrUtil.splitToInt(deviceId,StrUtil.C_COMMA);
            String[] deviceSns = StrUtil.splitToArray(deviceSn,StrUtil.C_COMMA);
            for (int i = 0; i < deviceSns.length; i++) {
                if (MqttHelper.containsSn(deviceSns[i])){
                    onlineDeviceIds.add(deviceIds[i]);
                }else {
                    offlineDeviceIds.add(deviceIds[i]);
                }
            }
        }
    }
}
